{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>分类列表</h5>
        </div>
        <div class="ibox-content">
            <!--搜索框开始-->           
            <div class="row">
                <div class="col-sm-12">   
                <div  class="col-sm-4" >
                    <div class="input-group" >  
                        <a onclick="add_news_id();"><button class="btn btn-outline btn-primary" type="button">添加</button></a> 
                        <input type="hidden" id="roleid" name="roleid" value="{$id}" />&nbsp;&nbsp;&nbsp;&nbsp;
                        <button type="button" class="btn" onclick="javascript:history.go(-1);"><i class="fa fa-search"></i> 返回</button>
                    </div>
                </div>                                                                    
                </div>
            </div>
            <!--搜索框结束-->
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="table table-bordered table-hover">
                        <thead>
                            <tr class="long-tr">
                                <th width="5%"><input type="checkbox" id="allCheck"  />全选 </th>
                                <th>ID</th>
                                <th>名称</th>
                                <th>排序</th>
                                <th>状态</th>
                                <th width="15%">添加时间</th>
                                <th width="15%">更新时间</th>
                            </tr>
                        </thead>
                        <tbody id="article_list">
                            {foreach name="list" item="vo"}
                                <tr class="long-td">
                                    <td><input type="checkbox" name="user_id"   sbid={$vo.id} /></td>
                                    <td>{$vo.id}</td>
                                    <td>{$vo.name}</td>
                                    <td>{$vo.orderby}</td>                                                              
                                    <td>
                                        {if condition="$vo['status'] == 1"}
                                            <a href="javascript:;" onclick="cate_state({$vo.id});">
                                                <div id="zt{$vo.id}"><span class="label label-info">开启</span></div>
                                            </a>
                                        {else/}    
                                            <a href="javascript:;" onclick="cate_state({$vo.id});">
                                                <div id="zt{$vo.id}"><span class="label label-danger">禁用</span></div>
                                            </a>
                                        {/if}   
                                    </td>
                                    <td>{$vo.create_time}</td>
                                    <td>{$vo.update_time}</td>
                                </tr>
                            {/foreach}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- End Panel Other -->
</div>
{include file="public/footer" /}


<script type="text/javascript">

$(function() {  
    $("#allCheck").click(function(){  
        obj = document.getElementById("allCheck");
        var objNameList=document.getElementsByName("user_id");
        if(null!=objNameList)
        {
         for(var i=0;i<objNameList.length;i++)
          {
           var obj1= objNameList[i];
       
        //    if(obj1.getAttribute("flag")==1){
            obj1.checked=obj.checked;
        //    }
          
          }

        }
     
    });  
});

function add_news_id()
  {
    var objNameList=document.getElementsByName("user_id");
        if(null!=objNameList)
        {
            var sbIdArr="";
            var count=0;
         for(var i=0;i<objNameList.length;i++)
          {
          var obj1= objNameList[i];
          if(obj1.checked==true)
          {
            count++;
            if(count==1)
            {
                sbIdArr=obj1.getAttribute("sbid");
            }else{
                sbIdArr=sbIdArr+","+obj1.getAttribute("sbid");
            }
          }
          }
         }

          if(sbIdArr==''){
            layer.msg('请先选择栏目', {icon: 5,time:1500,shade: 0.1}, function(index){
                  
         });
         }else{
             var cateid=$('#roleid').val();
            $.ajax({
                     type:"POST",
                     url:"/admin/role/add_article_cateid",
                     dataType:"json",
                     data:{article_cate_id:sbIdArr,id:cateid},
                     error:function(){
                         alert("错误");
                     },
                     success:function(data){
                         if(data.code==1){
                            window.location.href='/admin/role/index'
                         }
                     }
                 }); 
         }
  }

/**
 * [del 删除用户]
 * @Author[田建龙 864491238@qq.com]
 * @param   {[type]}    id [用户id]
 */
function del_cate(id){
    layer.confirm('确认删除此分类?', {icon: 3, title:'提示'}, function(index){
        //do something
        $.getJSON('./del_cate', {'id' : id}, function(res){
            if(res.code == 1){
                layer.msg(res.msg,{icon:1,time:1500,shade: 0.1},function(){
                    window.location.href="{:url('news/index_cate')}";
                });               
            }else{
                layer.msg(res.msg,{icon:0,time:1500,shade: 0.1});
            }
        });

        layer.close(index);
    })

}

/**
 * [user_state 用户状态]
 * @param  {[type]} val [description]
 * @Author[田建龙 864491238@qq.com]
 */
function cate_state(val){
    $.post('{:url("cate_state")}',
    {id:val},
    function(data){
         
        if(data.code==1){
            var a='<span class="label label-danger">禁用</span>'
            $('#zt'+val).html(a);
            layer.msg(data.msg,{icon:2,time:1500,shade: 0.1,});
            return false;
        }else{
            var b='<span class="label label-info">开启</span>'
            $('#zt'+val).html(b);
            layer.msg(data.msg,{icon:1,time:1500,shade: 0.1,});
            return false;
        }         
        
    });
    return false;
}


</script>
</body>
</html>